package com.example.anew.journey.mynewjourney.logic.splash;

import android.content.Intent;
import android.os.Handler;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.anew.journey.mynewjourney.R;
import com.example.anew.journey.mynewjourney.base.BaseRegisteredAndLoginActivity;
import com.example.anew.journey.mynewjourney.firstchangelogic.FirstChangeMain.FirstChangeMainActivity;
import com.example.anew.journey.mynewjourney.logic.registeredOrLogin.RegisteredOrLoginActivity;
import com.example.anew.journey.mynewjourney.logic.splash.persenter.SplashPersenter;
import com.example.anew.journey.mynewjourney.logic.splash.view.ISplashView;
import com.umeng.analytics.MobclickAgent;
import com.umeng.commonsdk.UMConfigure;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 杭州惟君医疗科技有限公司14
 * Created by 20433 on 2018/3/2
 *
 * @desc 闪屏界面
 */

public class SplashActivity extends BaseRegisteredAndLoginActivity implements ISplashView {
    @Bind(R.id.activity_splash_imageView)
    ImageView activitySplashImageView;
    @Bind(R.id.activity_splash_textView)
    TextView activitySplashTextView;
    private Handler mhandler = new Handler();
    private SplashPersenter mSplashPersenter = new SplashPersenter(this);

    /**
     * @desc 初始化数据 onCreate()
     */
    @Override
    protected void initView(View view) {

        UMConfigure.setLogEnabled(true);
        UMConfigure.setEncryptEnabled(true);
        MobclickAgent.setScenarioType(this, MobclickAgent.EScenarioType.E_DUM_NORMAL);
        MobclickAgent.setSessionContinueMillis(1000);
        displayToolbar();
        mSplashPersenter.requestNetwork(this);
    }

    /**
     * @desc 主要内容的布局资源填充进来
     */
    @Override
    protected View setMainContentView() {
        View view = View.inflate(this, R.layout.activity_splash, null);
        ButterKnife.bind(this,view);
        return view;
    }
    //页面跳转  Todo 注意是不是在主线程中执行  RegisteredOrLoginActivity
    @Override
    public void toRegisteredOrLoginActivity() {
        Intent intent = new Intent(SplashActivity.this, RegisteredOrLoginActivity.class);
        intent.putExtra("my_page_integration_code",0);
        intent.setFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT);
        startActivity(intent);
        finish();
    }
    // 设置图片  Todo 注意是不是在主线程中执行
    @Override
    public void SetLogoImageView(String str) {
        Glide.with(SplashActivity.this)
                .load(str)
                .error(R.mipmap.ic_launcher)
                .placeholder(R.mipmap.ic_launcher)
                .centerCrop()
                .into(activitySplashImageView);
    }
    // 页面动画  Todo 注意是不是在主线程中执行
    @Override
    public void PerformAnimation() {

    }
    //  提示信息
    @Override
    public void promptInformation(String str) {

    }

    @Override
    public void toMainPager() {
        Intent intent = new Intent(SplashActivity.this, FirstChangeMainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        startActivity(intent);
    }

    /**
     * @desc Activity 销毁 释放资源
     */
    @Override
    protected void releaseResources() {
        ButterKnife.unbind(this);
    }

}
